package com.smarthome.web.property.controller.workingmonitor;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smarthome.core.workingmonitor.EquipmentCommLogService;
import com.smarthome.domain.bean.ShEquipmentCommLog;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;
import com.smarthome.domain.vo.boss.TimeRange;
import com.smarthome.web.property.utils.UserHolder;

/**
 * 设备通讯日志控制类
* @ClassName: EquipmentCommLogController
* @Description: TODO
* @author cyj
* @date 2015年9月12日 下午3:36:29
*
 */
@Controller
@RequestMapping("/equipmentCommLogController")
public class EquipmentCommLogController {

	@Resource
	private EquipmentCommLogService equipmentCommLogService;
	
	/**
	 * 
	* dataGrid(获取设备通讯日志数据表格)
	* @Title: dataGrid
	* @Description: TODO
	* @param equipmentCommLog
	* @param page
	* @param request
	* @return
	* DataGrid
	* @throws
	* @author cyj
	* @date 2015年9月12日 下午4:11:44
	 */
	@RequestMapping("/dataGrid")
    @ResponseBody
    public DataGrid dataGrid(ShEquipmentCommLog equipmentCommLog, PageHelper page,TimeRange timeRange) {
		if(timeRange.getStartGmtModify() != null) {
			equipmentCommLog.addQueryData("startGmtModify", timeRange.getStartGmtModify());
    	}
    	if(timeRange.getEndGmtModify() != null) {
    		equipmentCommLog.addQueryData("endGmtModify", timeRange.getEndGmtModify());
    	}
    	Long residenceId = UserHolder.getCurrentResidenceId();
    	equipmentCommLog.addQueryData("residenceId", residenceId);
        return equipmentCommLogService.dataGrid(equipmentCommLog, page);
    }
	
	
    /**
     * 
    * @Title: getComboData 
    * @Description: TODO(获取日志同学类型需要的combo数据) 
    * @return
    * Map<String,Object>
    * @throws 
    * @author cyj
     */
    @RequestMapping("/getComboData")
    @ResponseBody
    public Map<String,Object> getComboData() {
    	Map<String,Object> result = new HashMap<>();
    	List<Combobox> equipmentType = equipmentCommLogService.equipmentTypeId(false);
    	result.put("equipmentType", equipmentType);
    	return result;
    }
	
	
}
